<?php


namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Controller;
use App\Services\Admin\PermissionService;
use Illuminate\Http\Request;

class PermissionController extends Controller
{
    private $permissionService;

    public function __construct(PermissionService $permissionService){
        $this->permissionService = $permissionService;
    }

    /**
     * 获取角色菜单
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function getMenuList(Request $request){
        $params = $request->input();
        $result = $this->permissionService->getMenuList($params);
        return $result;
    }

    /**
     * 获取所有菜单
     * @return array
     */
    public function getAllMenu(){
        $result = $this->permissionService->getAllMenu();
        return $result;
    }

    /**
     * 添加/更新菜单
     * @param Request $request
     * @return array
     */
    public function createOrUpdateMenu(Request $request){
        $params = $request->input();
        $result = $this->permissionService->createOrUpdateMenu($params);
        return $result;
    }

    /**
     * 删除菜单
     * @param Request $request
     * @return array
     */
    public function deleteMenu(Request $request){
        $result = $this->permissionService->deleteMenu($request->post('id'));
        return $result;
    }

}
